package com.xc.controller;

import com.xc.common.ServerResponse;
import com.xc.service.IStockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/16 8:15 PM
 */
@Controller
@RequestMapping("/api/stock/")
@Slf4j
public class StockApiController {

    @Autowired
    IStockService iStockService;

    /**
     *  获取大盘指数
     * @return
     */
    @RequestMapping("getMarket.do")
    @ResponseBody
    public ServerResponse getMarket(){
        return iStockService.getMarket();
    }

    /**
     *  分页获取 股票列表数据
     * @param pageNum
     * @param pageSize
     * @param keyWords
     * @return
     */
    @RequestMapping("getStock.do")
    @ResponseBody
    public ServerResponse getStock(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                 @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                 @RequestParam(value = "keyWords",required = false) String keyWords){
        return iStockService.getStock(pageNum , pageSize , keyWords);
    }

    /**
     *    通过股票代码获取单只股票的行情
     * @param code 股票代码
     * @return
     */
    @RequestMapping("getSingleStock.do")
    @ResponseBody
    public ServerResponse getSingleStock(@RequestParam("code") String code){
        return iStockService.getSingleStock(code);
    }

    /**
     *  获取股票 分钟K线
     * @param code 股票代码
     * @param time 分钟间隔（5、15、30、60）
     * @param ma   均值（5、10、15、20、25）
     * @param size 查询个数点（最大值242）
     * @return
     */
    @RequestMapping("getMinK.do")
    @ResponseBody
    public ServerResponse getMinK(@RequestParam("code") String code
                ,@RequestParam("time") Integer time
                ,@RequestParam("ma") Integer ma
                ,@RequestParam("size") Integer size
    ){
        return iStockService.getMinK(code,time,ma,size);
    }

    /**
     *  获取分钟K线，返回echarts vo
     * @param code
     * @param time
     * @param ma
     * @param size
     * @return
     */
    @RequestMapping("getMinK_Echarts.do")
    @ResponseBody
    public ServerResponse getMinK_Echarts(@RequestParam("code") String code
            ,@RequestParam("time") Integer time
            ,@RequestParam("ma") Integer ma
            ,@RequestParam("size") Integer size
    ){
        return iStockService.getMinK_Echarts(code,time,ma,size);
    }






}
